package com.yungu.swift.admin.route.marketing;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yungu.swift.assets.passenger.model.dto.PassengerRechargeDto;
import com.yungu.swift.assets.passenger.model.param.AdminPassengerRechargeParam;
import com.yungu.swift.assets.passenger.service.PassengerRechargeCityService;
import com.yungu.swift.base.ResponseData;
import com.yungu.swift.base.model.admin.AdminCityUuidParam;
import com.yungu.swift.utils.ParamUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collection;

import static com.yungu.swift.admin.consts.AdminErrorEnum.PARAM_ERROR;
import static com.yungu.swift.assets.passenger.model.enums.PassengerErrorEnum.RECHARGE_MONEY_ZERO;

/**
 * @author : cuixiuyin
 * @date : 2019/7/29
 */
@RestController
@RequestMapping("/admin/v1/marketing/passengerRecharge")
@Api(value = "【营销管理】", tags = "乘客充值管理")
public class PassengerRechargeAdmin {

    @Reference
    private PassengerRechargeCityService passengerRechargeCityService;

    @RequestMapping(value = "/template", method = RequestMethod.POST)
    @ApiOperation(value = "乘客充值模板列表", httpMethod = "POST")
    public ResponseData<Collection<PassengerRechargeDto>> detail(@RequestBody AdminCityUuidParam cityUuidParam) {
        return passengerRechargeCityService.findPassengerRechargeCity(cityUuidParam.getCityUuid());
    }

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ApiOperation(value = "乘客充值模板列表", httpMethod = "POST")
    public ResponseData<Boolean> save(@RequestBody AdminPassengerRechargeParam rechargeParam) {
        if (ParamUtil.isIllegal(rechargeParam.getGift(), rechargeParam.getMoney())) {
            return ResponseData.buildErrorResponse(PARAM_ERROR.getCode(), PARAM_ERROR.getMsg());
        }
        if (rechargeParam.getMoney() == 0.0) {
            return ResponseData.buildErrorResponse(RECHARGE_MONEY_ZERO.getCode(), RECHARGE_MONEY_ZERO.getMsg());
        }
        return passengerRechargeCityService.savaPassengerRechargeCity(rechargeParam);
    }


}
